package com.atguigu.lease.web.admin.custom.config;


import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.custom.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.interceptors.loginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//converter转换器的配置类
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private StringToItemTypeConverter stringToItemTypeConverter;
    @Autowired
    private StringToBaseEnumConverterFactory converterFactory;

    //从配置文件中读取拦截地址，放行地址
    @Value("${login.interceptor.includes}")
    private String [] includes ;

    @Value("${login.interceptor.excludes}")
    private String [] excludes ;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(stringToItemTypeConverter);
        registry.addConverterFactory(converterFactory);
    }

    //添加拦截器 指定拦截地址
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new loginInterceptor())
                .addPathPatterns("includes")
                .excludePathPatterns("excludes")
                .order(10);
    }
}
